home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Serious Software
/
OpenWorld demo 2.0
/
Development
/
DoubleTag
/
Applescript
/
APPLESCRIPT.c
next >
Wrap
Text File
|
1999-04-21
|
2KB
|
73 lines
/* File: Applescript.c
Copyright (c) 1999 Marco Bambini. All rights reserved.
Description: execute with Applescript the text between the <APPLESCRIPT> </APPLESCRIPT> tags
*/
#include "OpenWorld_plugIn.h"
#include <CodeFragments.h>
#include <OSA.h>
Boolean main (dataPtr param)
{
switch (param->message)
{
case init_message:
{
param->version=kVersion;
param->customData=kUnused;
}
break;
case run_message:
{
AEDesc sourceData,resultingData;
OSAError myOSAErr;
long flags;
if (param->scriptingComponent==NULL) return NULL;
if (param->dim==0) return NULL;
if (param->inputText==NULL) return NULL;
/* Prepare the descriptor parameter */
myOSAErr=AECreateDesc(typeChar,param->inputText,param->dim,&sourceData);
if (myOSAErr==noErr) flags=kOSAModeNeverInteract + kOSAModeCantSwitchLayer + kOSAModeDisplayForHumans ;
else return NULL;
/* Compile, execute and convert the result*/
myOSAErr=OSADoScript(param->scriptingComponent,&sourceData,kOSANullScript,typeChar,flags,&resultingData);
if (myOSAErr==errOSAScriptError) myOSAErr=OSAScriptError(param->scriptingComponent,kOSAErrorMessage,typeChar,&resultingData);
/* Allocate a return buffer */
if (myOSAErr==noErr) param->dim=GetHandleSize(resultingData.dataHandle);
else {param->dim=0;param->outputText=NULL;}
if (param->dim==0) param->outputText=NULL;
else param->outputText=OW_NewPtr(param,param->dim);
if (param->outputText!=NULL) BlockMove(*(resultingData.dataHandle),param->outputText,param->dim);
else {param->dim=0;param->outputText=NULL;}
/* Dispose unused buffers */
AEDisposeDesc(&sourceData);
AEDisposeDesc(&resultingData);
}
break;
case stop_message:
{
// dispose the buffer
OW_DisposePtr(param,param->outputText);
}
break;
case end_message:
{
// do nothing
}
break;
}
// Ask OpenWorld to send the text between <APPLESCRIPT> and </APPLESCRIPT> in the run_message
return kDoubleTag;
}